<?php
// +----------------------------------------------------------------------
// | Quotes [ 只为给用户更好的体验]**[我知道发出来有人会盗用,但请您留版权]
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 青涩  <3489621943@qq.com>          盗用不留版权,你就不配拿去!
// +----------------------------------------------------------------------
// | Date: 2021年03月24日
// +----------------------------------------------------------------------

include("./includes/common.php");
function success($data,$msg='获取成功'){
    echo json_encode(array_merge([
        'code'=>1,
        'msg'=>$msg
    ],$data));
    exit();
}
function error($msg){
    echo json_encode([
        'code'=>-1,
        'msg'=>$msg
    ]);
    exit();
}
$action = $_REQUEST['act'];
if($action=='Instant_Notify'){
    // file_put_contents(__DIR__.'/test.txt',var_export($_REQUEST,true)."\n",\FILE_APPEND);
    $type = $_REQUEST['type'];
    $pid = $_REQUEST['pid'];
    $money = $_REQUEST['money'];
    if($type and $pid and $money){
         $time  = time();
        $order=$DB->getRow("select * from ucenter_order where  type='$type' and pid = '$pid' and pay_money='$money'  and status=0 and  outtime>'$time'");
        //   file_put_contents(__DIR__.'/test2.txt',var_export($rows,true)."\n",\FILE_APPEND);
        // file_put_contents(__DIR__.'/test2.txt',"select * from ucenter_order where type='$type' and pid = '$pid' and money<='$money'  and status=0 and  outtime>'$time'"."\n",\FILE_APPEND);
        //  file_put_contents(__DIR__.'/test1.txt',var_export($rows,true)."\n",\FILE_APPEND);
      
        if($order){
            $id = $order['id'];
            $time = time();
            $res=$DB->exec("UPDATE ucenter_order SET status=1,endtime=$time WHERE id='$id'");
            
            $url = $order['notify_url'].'?'.http_build_query([
                'out_trade_no'=>$order['out_trade_no'],
                'pid'=>$order['pid'],
                'trade_no'=>$order['trade_no'],
                'type'=>$order['type'],
                'name'=>$order['name'],
                'money'=>$order['money'],
                'sign'=>$order['sign'],
                'trade_status'=>'TRADE_SUCCESS',
            ]);
            
            // file_put_contents(__DIR__.'/test1.txt',$url."\n",\FILE_APPEND);
            get_curl($url);
        }
    }
   
   
}